﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace ViaConvert
{
    public class Program
    {
        string FullPath = Path.Combine(Environment.CurrentDirectory, "..\\..\\data\\schema.xsd");
        static string csvData = AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\data\\sample.csv";
        static string xmlData = AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\data\\sample.xml";
        static string xmlData2 = AppDomain.CurrentDomain.BaseDirectory + "\\..\\..\\data\\xm.xml";        

        /// <summary>
        /// Console Application Entry Point
        /// </summary>
        /// <param name="args">...</param>
        static void Main(string[] args)
        {

            //CsvTest();
            //XmlTest();
            //XmlToCsv();
            CsvToXml();
            
        }

        static void CsvToXml()
        {
            var csv = Csv.Load.Init(csvData);

            var TestCase2_1 = from case1 in csv
                              select case1;

            List<Model.Csv.AddressInfo> models1 = TestCase2_1.ToList();


           Model.Xml.AddressInfo xmlModel =  Csv.Converter.ToXmlModel(models1);

        }

        static void XmlToCsv()
        {
            var xml = Xml.Load.Init(xmlData).City;

            var TestCase2_1 = from case1 in xml
                              select case1;

            Model.Xml.AddressInfo models1 = new Model.Xml.AddressInfo();

            models1.City = TestCase2_1.ToList();

            List<Model.Csv.AddressInfo> csvModel = Xml.Converter.ToCsvModel(models1);


        }
        
        static void XmlTest()
        {
            
            var xml = Xml.Load.Init(xmlData).City;

            var TestCase2_1 = from case1 in xml
                              select case1;

            var TestCase2_2 = from case1 in xml
                              orderby case1.name ascending
                              select case1;

            var TestCase2_3 = from case1 in TestCase2_2
                                from dis in case1.District
                                orderby dis.name ascending
                              select case1;

            Model.Xml.AddressInfo models1 = new Model.Xml.AddressInfo();
            models1.City = TestCase2_1.ToList();

            Model.Xml.AddressInfo models2 = new Model.Xml.AddressInfo();
            models2.City = TestCase2_2.ToList();

            Model.Xml.AddressInfo models3 = new Model.Xml.AddressInfo();
            models3.City = TestCase2_3.ToList();            

        }

        static void CsvTest()
        {
            

            var csv = Csv.Load.Init(csvData);

            //Generate CSV output from CSV input, sorted by City name ascending, then District name ascending


            var TestCase2_1 = from case1 in csv
                              select case1;

            var TestCase2_2 = from case1 in csv
                              orderby case1.CityName ascending
                              select case1;

            var TestCase2_3 = from case1 in TestCase2_2
                              orderby case1.DistrictName ascending
                              select case1;



            List<Model.Csv.AddressInfo> models1 = TestCase2_1.ToList();
            List<Model.Csv.AddressInfo> models2 = TestCase2_2.ToList();
            List<Model.Csv.AddressInfo> models3 = TestCase2_3.ToList();
        }        
    }
}
